// pages/mine/course/coursehour/index.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coursehour:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    var _this=this;
    app.paiRequest("/app/course/tcourses/detail", options).then(function (res) {
      let courseCover = res.data.courseCover;
      let courseItem = res.data.childList;
      let coursePrice = res.data.coursePrice;
      let courseContent = res.data.courseContent;
      let courseTitle = res.data.courseTitle;
      let teacherId = res.data.teacherId;
      _this.setData({
        courseCover: courseCover,
        coursehour: courseItem,
        coursePrice: coursePrice,
        courseContent: courseContent,
        courseTitle: courseTitle,
        teacherId: teacherId
      })
    })

    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  courseNav: function (e) {
    var coursehourseId = e.currentTarget.dataset.id;
    var courseHourseTitle = e.currentTarget.dataset.title;
    var codeId = e.currentTarget.dataset.parentcode;
    var coursetitle = '课程名称';
    var src = e.currentTarget.dataset.src;
    src = src + "?parentCode=" + coursehourseId + "&coursetitle=" + coursetitle;
   
    var sumitdata = {
      courseId: codeId,
      courseHourseId: coursehourseId,
      courseHourseTitle: courseHourseTitle,
      courseTitle: coursetitle
    };
    app.paiRequest("/app/course/exercise/user/save", sumitdata).then(function (res) {
      console.log(res);
      var data = res.data;
      src = src + "&exercisesId=" + data.id + "&courseId=" + codeId + "&courseHourseId=" + coursehourseId;
      wx.navigateTo({
        url: src,
      })
    })
  },
  selectHours: function (event) {
    var id = event.currentTarget.dataset.id;
    var parentcode = event.currentTarget.dataset.parentcode;
    var courseContent = this.data.courseContent;
    var courseTitle = this.data.courseTitle;
    var courseItem = this.data.courseItem;
    var teacherId = this.data.teacherId;
    let poster = this.data.courseCover;
    var sumitdata = {
      courseId: parentcode,
      courseHourseId: id
    };
    app.paiRequest("/app/course/study/tcourseStudy/startStudy", sumitdata).then(function (res) {
      var studyId = res.data.id;
      wx.navigateTo({
        url: '/pages/coursehourse/index?id=' + id + '&courseTitle=' + courseTitle + '&courseContent=' + courseContent + '&studyId=' + studyId + '&pauseTime=' + res.data.pauseTime + '&difference=' + res.data.difference + '&teacherId=' + teacherId + '&poster=' + poster,
      })
    })

  },
})